﻿var currentVideo = null;
var videoFrameTop = null;
var videoFrameRight = null;
var videoFrameBottom = null;
var videoFrameLeft = null;

function showVideo(e, movieUrl, movieTitle, movieSubtitle, movieNo, noOfMovies, atag) {
	if (e) {
		e.cancelBubble = true;
		e.returnValue = false;
	}
	if (e.stopPropagation) {
		e.stopPropagation();
		e.preventDefault();
	}
	currentVideo = atag;
	var attributes = {};
	var params = {
		wmode: "transparent"
	};
	var flashvars = {
		source: movieUrl,
		subtitles: movieSubtitle
	};
	showPlayer(params, flashvars, attributes, flashSwf, jQuery(atag).offset().top);

	videoFrameTop.innerHTML = "";
	if (movieNo > 1) {
		videoFrameRight.innerHTML = "<div class=\"right\"><a href=\"javascript:moveTo(-1);\">Vorige</a></div>";
	}
	else {
		videoFrameRight.innerHTML = "";
	}
	if (movieNo < noOfMovies) {
		videoFrameLeft.innerHTML = "<div class=\"left\"><a href=\"javascript:moveTo(+1);\">Volgende</a></div>";
	}
	else {
		videoFrameLeft.innerHTML = "";
	}
	videoFrameBottom.innerHTML = "<div class=\"paginering\">" + movieNo + "/" + noOfMovies + "</div><div class=\"titel\">" + movieTitle + "</div><div class=\"sluiten\"><a href=\"javascript:hideVideo();\">Sluiten</a></div>";
}

function showPlayer(params, flashvars, attributes, flashSwf, yoffset) {
	if (jQuery(".divPopupWindow:hidden").size() > 0) {
		jQuery(".divPopupWindow").slideDown(250);
	}
	if (jQuery(".divPopupBackground:hidden").size() > 0) {
		jQuery(".divPopupBackground").css("opacity", 0);
		jQuery(".divPopupBackground").animate({ opacity: 0.5 }, 250);
		jQuery(".divPopupBackground").show();
	}
	if (swfobject.getFlashPlayerVersion().major >= 9) {
		swfobject.embedSWF(flashSwf, "Flash", "840", "473", "9.0.0", "/flash/expressInstall.swf", flashvars, params, attributes);
		jQuery(".divPopupWindow").css("margin-left", "-440px")
		if (typeof (yoffset) == "number") {
			jQuery(".divPopupWindow").css("top", (yoffset - 350) + "px")
		}
	}
}

function hideVideo() {
	jQuery(".divPopupWindow").hide()
	jQuery(".divPopupBackground").hide()
	jQuery("#FlashHolder").html("<div id=\"Flash\"></div>");
}

function moveTo(direction) {
	var selector = "#" + currentVideo.id;
	if (direction == -1) {
		jQuery(selector).prev().click()
	}
	else {
		jQuery(selector).next().click()
	}
}


// ******************************************
// Flash Video User Control
// ******************************************

function InitFlashVideoDivs() {
	if (jQuery("div.divPopupBackground").size() == 0) {
		var htmlCode = "<div class=\"divPopupBackground\" id=\"divPopupBackground\"></div>\n";
		htmlCode += "<div class=\"divPopupWindow\" id=\"divPopupWindow\">\n";
		htmlCode += "<div class=\"videoFrameTop\" id=\"videoFrameTop\"></div>\n";
		htmlCode += "<div class=\"videoFrameLeft\" id=\"videoFrameLeft\"></div>\n";
		htmlCode += "<div class=\"videoFrameRight\" id=\"videoFrameRight\"></div>\n";
		htmlCode += "<div id=\"FlashHolder\">\n";
		htmlCode += "<div id=\"Flash\"></div>\n";
		htmlCode += "</div>\n";
		htmlCode += "<div class=\"videoFrameBottom\" id=\"videoFrameBottom\"></div>\n";
		htmlCode += "</div>\n";

		jQuery(htmlCode).appendTo("body");
		
		videoFrameTop = document.getElementById("videoFrameTop");
		videoFrameRight = document.getElementById("videoFrameRight");
		videoFrameBottom = document.getElementById("videoFrameBottom");
		videoFrameLeft = document.getElementById("videoFrameLeft");
	}
}

// ******************************************
// Algemeen
// ******************************************

// adds the specified function to the onload function of the window with
// while retaining already specified onload functions.
function addOnloadEvent(fnc) {
	if (typeof window.addEventListener != "undefined")
		window.addEventListener("load", fnc, false);
	else if (typeof window.attachEvent != "undefined") {
		window.attachEvent("onload", fnc);
	}
	else {
		if (window.onload != null) {
			var oldOnload = window.onload;
			window.onload = function(e) {
				oldOnload(e);
				window[fnc]();
			};
		}
		else
			window.onload = fnc;
	}
}